package com.licq.hongmeng.slice;

import com.licq.hongmeng.ResourceTable;
import com.licq.hongmeng.bean.BaseBean;
import com.licq.hongmeng.bean.JokeBean;
import com.licq.hongmeng.data.ListHolder;
import com.licq.hongmeng.net.MobileApi;
import com.licq.hongmeng.net.NetInheritObserver;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import retrofit2.Call;

import java.util.ArrayList;

public class MainAbilitySlice extends AbilitySlice {
    private ListHolder listHolder;

    @Override
    public void onStart(Intent intent) {
        listHolder = new ListHolder(this);
//        setUIContent(ResourceTable.Layout_ability_main_helloworld);
        listHolder = new ListHolder(this);
        setUIContent(listHolder.createComponent());
//        Text componentById = (Text) findComponentById(ResourceTable.Id_helloworld);

        MobileApi.getInstance().getJoke(1,20,"video")
                .enqueue(new NetInheritObserver<BaseBean<ArrayList<JokeBean>>>(getContext()){
            @Override
            public void onSubscribed(Call disposable) {

            }

            @Override
            public void onSuccess(BaseBean<ArrayList<JokeBean>> arrayListBaseBean, String errorMsg) {
                StringBuilder stringBuilder = new StringBuilder();
                for (JokeBean jokeBean : arrayListBaseBean.getResult()){
                    HiLog.debug(new HiLogLabel(HiLog.DEBUG,1,"licq"),jokeBean.getName());
                    stringBuilder.append(jokeBean.getName());
                }
//                componentById.setText(stringBuilder.toString());
            }

            @Override
            public void onFail(String msg) {
                HiLog.debug(new HiLogLabel(HiLog.DEBUG,1,"licq"),msg);
            }

        });
//        HiLog.debug(new HiLogLabel(HiLog.DEBUG,1,"licq"),"onItemClicked");
//        Intent secondIntent = new Intent();
//        // 指定待启动FA  的bundleName和abilityName
//        Operation operation = new Intent.OperationBuilder()
//                .withDeviceId("")
//                .withBundleName("com.licq.hongment")
//                .withAbilityName("com.licq.hongment.VideoPlayerAbility")
//                .build();
//
//        secondIntent.setOperation(operation);
//        startAbility(secondIntent); // 通过AbilitySlice的startAbility接口实现启动另一个页面
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
